<?php

class Css extends Controller {
	
	function __construct(){
		parent::__construct();
		
		$this->load->driver('cache', 
			array('adapter' => 'apc', 'backup' => 'file')
		);		
	}
	
	function _remap($method){
		$this->_inlinecss($method);
		
		$this->load->driver('cache', 
			array('adapter' => 'apc', 'backup' => 'file')
		);
	}
	
	function _inlinecss($checksum=null){
		if(is_null($checksum))
			show_404();
			
		$checksum = str_replace(".css","", $checksum);
		
		$this->load->driver('cache');
		
		$content =  $this->cache->get($checksum);

		if(!$content)
			show_404();

		$this->output->set_header('Content-type: text/css');
		$this->output->set_header("Cache-Control: public");
		$this->output->set_header("Pragma: public"); 

		$expire_date = date("D, d M Y H:i:s e", time() + (20*24*60*60) );
		
		$this->output->set_header("Expires: {$expire_date}");
		$this->output->set_header("Etag: {$checksum}");
		
		$this->output->cache(20*24*60);

		ci_echo($content);

		$this->cache->delete($checksum);
	}
	
}